import json


class BaseKfMessage(object):
    def __init__(self, to_user):
        info = dict()
        info['touser'] = to_user
        self.info = info

    def to_json(self):
        return json.dumps(self.info, ensure_ascii=False).encode('utf-8')


class KfTextMessage(BaseKfMessage):
    def __init__(self, to_user, text):
        BaseKfMessage.__init__(self, to_user)
        other_field = {
            'msgtype': 'text',
            'text': {
                'content': text
            }
        }
        self.info = dict(self.info, **other_field)


class KfImageMessage(BaseKfMessage):
    def __init__(self, to_user, image_id):
        BaseKfMessage.__init__(self, to_user)
        other_field = {
            'msgtype': 'image',
            'image': {
                'media_id': image_id
            }
        }
        self.info = dict(self.info, **other_field)


class KfVoiceMessage(BaseKfMessage):
    def __init__(self, to_user, voice_id):
        BaseKfMessage.__init__(self, to_user)
        other_field = {
            'msgtype': 'voice',
            'image': {
                'media_id': voice_id
            }
        }
        self.info = dict(self.info, **other_field)


class KfMusicMessage(BaseKfMessage):
    def __init__(self, to_user, music_info):
        BaseKfMessage.__init__(self, to_user)
        other_field = {
            'msgtype': 'music',
            'music': music_info
        }
        self.info = dict(self.info, **other_field)


class KfNewsMessage(BaseKfMessage):
    def __init__(self, to_user, news):
        BaseKfMessage.__init__(self, to_user)
        other_field = {
            'msgtype': 'news',
            'news': news
        }
        self.info = dict(self.info, **other_field)




